package net.lunjin.service.impl;

import java.math.BigDecimal;

import net.lunjin.bean.News;
import net.lunjin.bean.NewsRemark;
import net.lunjin.bean.NewsRemarkTemplate;
import net.lunjin.dao.NewsDao;
import net.lunjin.dao.NewsRemarkDao;
import net.lunjin.dao.NewsRemarkTemplateDao;
import net.lunjin.service.NewsRemarkService;
import net.lunjin.util.ProjectUtil;

import org.springframework.beans.factory.annotation.Autowired;

import finaler.util.DateUtil;
import finaler.util.Page;
import finaler.util.PageList;

public class NewsRemarkServiceImpl implements NewsRemarkService {

	@Autowired
	private NewsDao newsDao;

	@Autowired
	private NewsRemarkDao newsRemarkDao;

	@Autowired
	private NewsRemarkTemplateDao newsRemarkTemplateDao;

	@Override
	public PageList getNewsRemarkList(Page page) throws Exception {
		return newsRemarkDao.getNewsRemarkList(page);
	}

	@Override
	public boolean insert(NewsRemark remark) throws Exception {
		return newsRemarkDao.insert(remark);
	}

	@Override
	public void deleteRemark(BigDecimal newsId)throws Exception  {
		newsRemarkDao.deleteRemark(newsId);
	}

	@Override
	public void autoBbsRemark() throws Exception {
		News news = newsDao.getRandomBBSRecord();//随机获得一个论坛贴子
		if(news==null){return;}
		NewsRemarkTemplate newsRemarkTemplate = newsRemarkTemplateDao.getRandomRecord();//随机获得一个评论模板
		if(newsRemarkTemplate==null){return;}
		NewsRemark newsRemark = new NewsRemark();
		newsRemark.setAutoflag(new BigDecimal(1));
		newsRemark.setCreatetime(DateUtil.getCurrentDate("yyyy-MM-dd HH:mm:ss"));
		newsRemark.setCreateuser(ProjectUtil.getRandomIP());
		newsRemark.setNewsid(news.getId());
		newsRemark.setRmcontent(newsRemarkTemplate.getRmcontent());
		newsRemarkDao.insert(newsRemark);
	}
	
}
